#include "ShadowMappingTechnique.h"


ShadowMappingTechnique::ShadowMappingTechnique(void)
{
}


ShadowMappingTechnique::~ShadowMappingTechnique(void)
{
}


bool ShadowMappingTechnique::Init()
{
	if(!Technique::Init())
	{
		std::cout << "ShadowMappingTechnique: failed at Init()" << std::endl;
		if (std::cin.get() == '\n')		
			return false;
	}

	
	if(!AddShader(GL_VERTEX_SHADER, "Shader/Shadow/ShadowMapping.vertexshader"))
	{
		std::cout << "ShadowMappingTechnique: AddShader(vertex) failed" << std::endl;
		if (std::cin.get() == '\n')		
			return false;
	}
	
	if(!AddShader(GL_FRAGMENT_SHADER, "Shader/Shadow/ShadowMapping.fragmentshader"))
	{
		std::cout << "ShadowMappingTechnique: AddShader(fragment) failed" << std::endl;
		if (std::cin.get() == '\n')		
			return false;
	}

	if(!Finalize())
	{
		std::cout << "ShadowMappingTechnique: Finalize failed" << std::endl;
		if (std::cin.get() == '\n')		
			return false;
	}

	m_textureLocation = GetUniformLocation("myTextureSampler");
	m_MatrixID = GetUniformLocation("MVP");
	m_ViewMatrixID = GetUniformLocation("V");
	m_ModelMatrixID = GetUniformLocation("M");
	m_DepthBiasID = GetUniformLocation("DepthBiasMVP");
	m_ShadowMapID = GetUniformLocation("shadowMap");
	m_lightInvDirID = GetUniformLocation("LightInvDirection_worldspace");
	

	return true;
}

	void ShadowMappingTechnique::setMatrixID(const glm::mat4& MVP)
	{
		glUniformMatrix4fv(m_MatrixID, 1, GL_FALSE, &MVP[0][0]);
	}

	void ShadowMappingTechnique::setViewMatrixID(const glm::mat4& ModelMatrix)
	{
		glUniformMatrix4fv(m_ModelMatrixID, 1, GL_FALSE, &ModelMatrix[0][0]);
	}

	void ShadowMappingTechnique::setModelMatrixID(const glm::mat4& ViewMatrix)
	{
		glUniformMatrix4fv(m_ViewMatrixID, 1, GL_FALSE, &ViewMatrix[0][0]);
	}

	void ShadowMappingTechnique::setDepthBiasID(const glm::mat4& depthBiasMVP)
	{
		glUniformMatrix4fv(m_DepthBiasID, 1, GL_FALSE, &depthBiasMVP[0][0]);
	}

	void ShadowMappingTechnique::setShadowMapID(unsigned int shadowMapID)
	{
		glUniform1i(m_ShadowMapID, shadowMapID);
	}

	void ShadowMappingTechnique::setlightInvDirID(glm::vec3 lightInvDir)
	{
		glUniform3f(m_lightInvDirID, lightInvDir.x, lightInvDir.y, lightInvDir.z);
	}

	void ShadowMappingTechnique::SetTextureUnit(unsigned int TextureUnit)
	{
		glUniform1i(m_textureLocation, TextureUnit);
	}
